<? include("../../MerchandiseBay/conn.php");?>



<?
if(isset($_REQUEST['category']))
 {
  $category=$_REQUEST['category'];
  /*$sqlMerchandise="select * from merchandise where category='$category' and sold_date='00000000'";*/
  $sqlMerchandise="select * from merchandise where category='$category'";
  $sqlMerchandise2="select count(*) As totalRow from merchandise where category='$category'";
  $qryMerchandise2=mysql_query($sqlMerchandise2,$conn);
  $qryMerchandise=mysql_query($sqlMerchandise,$conn);
  $row2=mysql_fetch_assoc($qryMerchandise2);

	if($row2["totalRow"] <= 0)
	{
		echo "<script type='text/javascript'>
		window.alert('Not items were found under this category.');
		history.back(1);
		</script>";
		exit;
	}
 }
else{$category="none";}

$sqlCategory="select category from category order by category";
$qryCategory=mysql_query($sqlCategory,$conn);

?>
<HEAD>
<script language="javascript" type="text/javascript">

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

</script>
<TITLE>Untitled Document</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE type=text/css>BODY {
	COLOR: #ffff00
}
TD {
	COLOR: #ffff00
}
TH {
	COLOR: #ffff00
}
BODY {
	BACKGROUND-COLOR: #0099FF}
</STYLE>

<META content="MSHTML 6.00.2900.2523" name=GENERATOR></HEAD>
<BODY link="#FFCC00">

<table border="0" width="100%" id="table1">
	<tr>
		<td height="52">
		<form method="POST" action="listProduct.php">
			
			<p>&nbsp;<select size="1" name="category">
			<? while($rowCategory=mysql_fetch_assoc($qryCategory)){
					if (strcmp ($category, $rowCategory['category']) == 0)
					{ ?>
					<option selected><?=$rowCategory['category']?></option>
					<?}
					else { ?>
					  <option><?=$rowCategory['category']?></option>
					<?}}?>
					</select>
			</select>&nbsp; <font face="Verdana"> 
			<input type="submit" value="View" name="B1" style="font-family: Verdana; font-size: 10px"></font> </p>
		</form>
		</td>
	</tr>
	<tr>
		<td>
		<table border="0" width="100%" id="table2">
        <?if($category!="none") {?>
        <tr>
          <td width="231" valign="top" bgcolor="#333333"><b><font size="2" face="Verdana">Food Code</font></b></td>
          <td width="233" valign="top" bgcolor="#333333"><b><font size="2" face="Verdana">Category</font></b></td>
          <td width="201" bgcolor="#333333" valign="top"><strong><font size="2" face="Verdana">Kind</font></strong></td>
          <td width="117" bgcolor="#333333" valign="top"><b> <font size="2" face="Verdana">Price</font></b></td>
          <td bgcolor="#333333" valign="top" width="163"><strong><font size="2" face="Verdana">Picture</font></strong></td>
        </tr>
        <? 
		while($rowMerchandise=mysql_fetch_assoc($qryMerchandise)){

			?>
        <tr>
          <td valign="top"><font face="Verdana" size="2" color="#FFFFFF"> &nbsp; 
            <?=$rowMerchandise['regno']?>
            </font></td>
          <td valign="top"><font face="Verdana" size="2" color="#FFFFFF">&nbsp; 
            <?=$rowMerchandise['category']?>
            </font></td>
          <td width="201" valign="top"> <font face="Verdana" size="2" color="#FFFFFF">&nbsp; 
            <?=$rowMerchandise['kind']?>
            </font></td>
          <td width="117" valign="top"> <font size="2" face="Verdana" color="#FFFFFF"> 
            <?=$rowMerchandise['price']?>
            </font></td>
          <td valign="top" width="163"> <font face="Verdana" size="2" color="#FFFFFF">&nbsp;<a href="productDetail.php?d=<?=$rowMerchandise['id']?>" onClick="NewWindow(this.href,'mywin','800','600','yes','center');return false" onFocus="this.blur()"><img src="productpic/<?=$rowMerchandise['pic']?>" alt="<?=$rowMerchandise['kind']?>" border="1" hspace="7" vspace="2" width="67" height="67"></a></font></td>
        </tr>
        <? }
			if(mysql_num_rows($qryMerchandise)==0) {?>
        <tr> 
          <td colspan="5"> <p align="center"><b><font size="3" face="Verdana" color="#00FFFF">&nbsp;</font></b><font size="3" face="Gill Sans MT" color="#00FFFF"><strong><font color="#66FF00" size="4">Information 
              about 
              <?=$category?>
              Not Exist In Record!</font></strong></font> </td>
        </tr>
        <?}?>
      </table>
		
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
</table>
<? } else
	  {
        $sqlCategory="select category from category order by category";
        $qryCategory=mysql_query($sqlCategory,$conn);
	  
	  ?>
<table border="0" width="79%" id="table3">
	<tr>
		
    <td><b><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Please choose one kind of FOOD to view. </font></b></td>
	</tr>
	<? while($rowCategory=mysql_fetch_assoc($qryCategory)){ ?>
	<tr>
		<td><font size="2" face="Verdana" color="#333333">&nbsp;&nbsp;&nbsp;&nbsp;<a href="listProduct.php?category=<?=$rowCategory['category']?>"><?=$rowCategory['category']?></a></font></td>
	</tr>
	<?}?>
</table>
<? }?>

</BODY></HTML>